package lanQiaoBei.搜索与图论.dfs;
import java.io.*;
/*N皇后问题
*最原始做法 枚举每个格子是否放皇后
* */
public class P2 {
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    final static int N=20;
    static int n;
    static boolean []row=new boolean[N],col=new boolean[N],dj=new boolean[N],udj=new boolean[N];
    static char[][]g=new char[N][N];

    static void dfs(int x,int y,int d){
           if(y==n){
               x++;
               y=0;
           }
           if(x==n){
               if(d==n){
                   for(int i=0;i<n;i++)
                       System.out.println(g[i]);
                   System.out.println();
               }
               return;
           }
           //该坐标的格子不放皇后
           dfs(x,y+1,d);
           //该坐标的格子放皇后+剪枝
           if(!row[x]&&!col[y]&&!dj[x+y]&&!udj[y-x+n]){
               g[x][y]='Q';
               row[x]=col[y]=dj[x+y]=udj[y-x+n]=true;
               dfs(x,y+1,d+1);
               g[x][y]='.';
               row[x]=col[y]=dj[x+y]=udj[y-x+n]=false;
           }
    }
    public static void main(String[]args)throws Exception{
           n=Integer.parseInt(br.readLine());
           for(int i=0;i<n;i++)
               for(int j=0;j<n;j++)
                   g[i][j]='.';
           dfs(0,0,0);
    }
}
